let App = getApp();

Page({
  data: {
    // banner轮播组件属性
    indicatorDots: true, // 是否显示面板指示点	
    autoplay: true, // 是否自动切换
    interval: 3000, // 自动切换时间间隔
    duration: 800, // 滑动动画时长
    imgHeights: {}, // 图片的高度
    imgCurrent: {}, // 当前banne所在滑块指针

    // 页面元素
    items: {},
    newest: {},
    best: {},
    meetingList: {},
    talentList: {},
    arr: ["全职", "兼职"],
    coupon: '',
    role: 1,

    scrollTop: 0,
  },

  onLoad: function (option) {
    // 设置页面标题
    // App.setTitle();
    // 设置navbar标题、颜色
    // App.setNavigationBar();
    // 获取首页数据
    this.getIndexData();
    
    //this.data.role = App.globalData.role;
    console.info("role", App.globalData.role);
    console.info("items", this.data.newest);
    console.info("items", this.data.items);
   wx.showShareMenu({
     withShareTicket: true 
   });



  },
  /**
   * 获取首页数据
   */
  getIndexData: function () {
    let _this = this;
    App._get('index/page', {}, function (result) {
      let temp = result.data.best;
      console.info("result.data", result.data);
      result.data.best[0].goods_name = result.data.best[0].goods_name.substring(0, 7);
      result.data.best[1].goods_name = result.data.best[1].goods_name.substring(0, 7);
      result.data.best[2].goods_name = result.data.best[2].goods_name.substring(0, 7);
      result.data.coupon.erffective_time = App.timeformat2(result.data.coupon.erffective_time);
      result.data.coupon.start_time = App.timeformat2(result.data.coupon.start_time);
      let roleT = App.globalData.role;
      _this.setData({
        role: roleT
      });
      console.info("role", _this.data.role);
      console.info("roleT", roleT);
      _this.setData(result.data);

    });
    App._get('trainMeeting/type/0', {}, function (result1) {
      console.log("_this.data.list.length", result1.data);

      for (var i in result1.data) {
        result1.data[i].meeting_date = App.timeformatG(result1.data[i].meeting_date);
      }
      _this.setData({
        meetingList: result1.data
      });

      console.log("meetingList", _this.data.meetingList);
    });


    App._get('talentshare/get/' + 1 + '/' + 1, {}, function (result2) {

      console.info("result2.data", result2.data);

      for (var i in result2.data) {
        result2.data[i].talentshare.create_time = App.timeformat(result2.data[i].talentshare.create_time);

      }
      _this.setData({
        talentList: result2.data
      });
      console.log("talentList", _this.data.talentList);
    });
  },
  getCoupon: function (event) {
    console.info("event", event);
    let id = event.target.dataset.id;
    console.info("id", id);
    App._get('couponUser/add/' + id, {}, function (result) {
      console.info("result", result);
      wx.showToast({
        title: result.message,
        icon: 'none',
        duration: 3000
      })
    })
  },
  /**
   * 计算图片高度
   */
  imagesHeight: function (e) {
    let min;
    let imgId = e.target.dataset.id,
      itemKey = e.target.dataset.itemKey,
      ratio = e.detail.width / e.detail.height, // 宽高比
      viewHeight = 750 / ratio, // 计算的高度值

      imgHeights = this.data.imgHeights;

    // 把每一张图片的对应的高度记录到数组里
    if (typeof imgHeights[itemKey] === 'undefined') {
      imgHeights[itemKey] = {};
    }
    imgHeights[itemKey][imgId] = 468.54663774403474;
    // 第一种方式
    let imgCurrent = this.data.imgCurrent;
    if (typeof imgCurrent[itemKey] === 'undefined') {
      imgCurrent[itemKey] = Object.keys(this.data.items[itemKey].data)[0];
    }
    this.setData({
      imgHeights,
      imgCurrent
    });
    console.info("this.data.items", this.data.items);
  },

  bindChange: function (e) {
    let itemKey = e.target.dataset.itemKey,
      imgCurrent = this.data.imgCurrent;
    // imgCurrent[itemKey] = e.detail.current;
    imgCurrent[itemKey] = e.detail.currentItemId;
    this.setData({
      imgCurrent
    });
  },

  goTop: function (t) {
    this.setData({
      scrollTop: 0
    });
  },

  scroll: function (t) {
    this.setData({
      indexSearch: t.detail.scrollTop
    }), t.detail.scrollTop > 300 ? this.setData({
      floorstatus: !0
    }) : this.setData({
      floorstatus: !1
    });
  },

  onShareAppMessage: function () {
    return {
      title: "琅氏·颌楽",
      desc: "",
      path: '/pages/login/userLogin?recommendId=' + App.globalData.user_id,
    };
  }
});